<?php
/*
	Copyright 2006, 2007, 2008, 2009, 2010 Bastiaan Grutters
    
    This file is part of Ages of Strife website.

    Ages of Strife website is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    Ages of Strife website is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Ages of Strife website.  If not, see <http://www.gnu.org/licenses/>.
 */
include( "../global/initialize.php");

aos_header( 'Militia' );

printGlobalSoldiers( $_SESSION[ 'ruler_id' ] );
include( '../global/resources.php' );
$statement = $dal->prepare( 'SELECT village_id, name, militia, start_place  
			FROM village 
			WHERE ruler_id = :ruler_id 
			ORDER BY name' );
$statement->bindParam( ':ruler_id', $_SESSION[ 'ruler_id' ], PDO::PARAM_INT );
$villages = $dal->getArrayOfObjects( $statement );
$currentTurn = getCurrentTurn();
?>
				<br />
				<div class="blok">
					<strong><?php transprint( 'Militia' ); ?></strong><br />
<?php
foreach( $villages AS $village ) {
?>
					<a href="../villages/village.php?name=<?php print( $village->name ); ?>"><strong class="green"><?php print( $village->name ); ?></strong></a><?php print( $village->start_place == 1 ? ' (' . translate( 'Capital' ) . ')' : '' ); ?><br />
<?php
	if( $village->militia > $currentTurn ) {
		// Militia present
		$timeout = $village->militia - $currentTurn;
?>
					<?php transprint( 'Guarded by a militia' ); ?><br />
					<?php transprint( 'Militia remains for' ); ?> <?php print( $timeout ); ?> <?php transprint( $timeout == 1 ? 'day' : 'days' ); ?><br />
<?php		
	}
	elseif( $village->militia + 24 <= $currentTurn ) {
		// No militia present
?>
					<form method="post" action="fund_militia.php">
						<input type="hidden" name="village_id" value="<?php print( $village->village_id ); ?>" />
						<?php transprint( 'Cost' ); ?>: <strong class="gold"><?php print( $village->start_place == 1 ? '3,000' : '6,000' ); ?></strong><br />
						<?php transprint( 'Duration' ); ?>: 72 <?php transprint( 'days' ); ?><br />
						<small>(<?php transprint( 'After 72 days or a large battle the militia will fall apart. It can be reformed 24 days later.' ); ?>)</small><br />
						<input type="submit" value="<?php transprint( 'Fund militia' ); ?>" /><br />
					</form>
<?php					
	}
	else {
		$cooldown = $village->militia + 24 - $currentTurn;
?>
					<?php transprint( 'Militia can be formed here in' ); ?> <?php print( $cooldown ); ?> <?php transprint( ( $cooldown == 1 ? 'day' : 'days' ) ); ?><br />
<?php
	}
?>
					<br />
<?php
}
?>					
				</div>
<?php 
aos_footer();